﻿using Abs.Core.Models.User;
using NUnit.Framework;

namespace Abs.Core.UnitTesting
{
    //[TestFixture]
    public class UserManagement
    {
        private Management.UserManagement ManageUser { get; set; }
        private string Email { get; set; }
        private string Password { get; set; }
        private string Name { get; set; }
        private int RoleId { get; set; }

        //[TestFixtureSetUp]
        public void BeforeTests()
        {
            this.ManageUser = Management.Manage.User;
            this.Email = "toph@abs.com";
            this.Password = "123456";
            this.Name = "Toph";
            this.RoleId = (int) RoleEnum.Admin;
        }//end of public void BeforeTests()

        //[Test]
        public void CreateUser()
        {
            var isSuccess = this.ManageUser.Create(this.Email,
                                                   this.Password,
                                                   this.Name);
            Assert.True(isSuccess);
        }//end of public void CreateUser()

        //[Test]
        public void DuplicateCreateUser()
        {
            var isSuccess = this.ManageUser.Create(this.Email,
                                                   this.Password,
                                                   this.Name);
            Assert.False(isSuccess);
        }//end of public void CreateDuplicateUser()

        //[Test]
        public void EditExistingUser()
        {
            var isSuccess = this.ManageUser.Update(this.Email,
                                                   this.Name,
                                                   this.RoleId);
            Assert.True(isSuccess);
        }//end of public void EditExistingUser()

        //[Test]
        public void EditNoExistingUser()
        {
            var isSuccess = this.ManageUser.Update("cat@abs.com",
                                                   this.Name,
                                                   this.RoleId);
            Assert.False(isSuccess);
        }//end of public void EditNoExistingUser()

        //[Test]
        public void ReadAllUsers()
        {
            var totalUsers = this.ManageUser.SelectAll().Count;
            var expectedTotalUsers = 11;
            Assert.AreEqual(expectedTotalUsers, totalUsers);
        }//end of public void ReadAllUsers()

        //[Test]
        public void ReadExistingUser()
        {
            var user = this.ManageUser.Select(this.Email);
            Assert.IsNotNull(user);
        }//end of public void ReadExistingUser()

        //[Test]
        public void ReadNoExistingUser()
        {
            var user = this.ManageUser.Select("cat@abs.com");
            Assert.IsNull(user);
        }//end of public void ReadNoExistingUser()

        //[Test]
        public void RemoveExistingUser()
        {
            var isSuccess = this.ManageUser.Delete(this.Email);
            Assert.IsTrue(isSuccess);
        }//end of public void RemoveExistingUser()

        //[Test]
        public void RemoveNoExistinguser()
        {
            var isSuccess = this.ManageUser.Delete("cat@abs.com");
            Assert.IsFalse(isSuccess);
        }//end of public void RemoveNoExistinguser()

        //[Test]
        public void LogInExistingUser()
        {
            var user = this.ManageUser.LogIn(this.Email,
                                             this.Password);
            Assert.IsNotNull(user);
        }//end of public void LogIn()

        //[Test]
        public void LogInNoExistingUser()
        {
            var user = this.ManageUser.LogIn("cat@abs.com",
                                             this.Password);
            Assert.IsNull(user);
        }//end of public void LogIn()
    }//end of internal class UserRepository
}//end of namespace